package com.gitee.huanminabc.jcommon.fastjson;

import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.gitee.huanminabc.jcommon.model.Money;

import java.lang.reflect.Type;
import java.math.BigDecimal;

/**
 * @description:
 * @author: huanmin
 * @create: 2025-04-17 22:14
 **/
public class MoneyObjectReader implements ObjectDeserializer {
    @Override
    public Money deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
        BigDecimal bigDecimal = parser.parseObject(BigDecimal.class);
        return Money.of(bigDecimal);
    }

    @Override
    public int getFastMatchToken() {
        return JSONToken.LITERAL_FLOAT;
    }
}
